#include <linux/types.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/queue.h>

struct entry{
	int data;
	LIST_ENTRY(entry) entries;
};

int main()
{
	struct entry *p = NULL;

	LIST_HEAD(listhead, entry) head;
//	struct listhead *headp;

	LIST_INIT(&head);

	while(1)
	{
		struct entry *pCusor;
		int input;

		printf("List entry : ");
		LIST_FOREACH(pCusor, &head, entries){
			printf("%d ", pCusor->data);
		}
		printf("\n");

		scanf("%d", &input);

		if(input == -1)
			break;
		else if(input == 0) {
			/*clear list*/
			LIST_INIT(&head);	
		}
		else {
			/*insert input at first of list*/
			struct entry *n1;
			n1 = (struct entry *)malloc(sizeof(struct entry));

			n1->data = input;
			LIST_INSERT_HEAD(&head, n1, entries);

		}
	
	}

}